package com.sinosoft.perfect.system._display.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import com.sinosoft.perfect.common.system.BaseAction;
import com.sinosoft.perfect.system._.po.TResourceSystem;
import com.sinosoft.perfect.system._.service.ILoginUserResourceService;
import com.sinosoft.perfect.system._display.dataFormat.IModel2TreeDataFormat;

@SuppressWarnings("serial")
public class Model2TreeAction extends BaseAction {

	private ILoginUserResourceService iloginUserResourceService;

	private IModel2TreeDataFormat model2TreeDataFormat;

	public void setIloginUserResourceService(ILoginUserResourceService iloginUserResourceService) {
		this.iloginUserResourceService = iloginUserResourceService;
	}

	public void setModel2TreeDataFormat(IModel2TreeDataFormat model2TreeDataFormat) {
		this.model2TreeDataFormat = model2TreeDataFormat;
	}

	public String initXmlLoginUserResource() throws IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		String resultXml = null;
		try {
			List<TResourceSystem> resources = iloginUserResourceService.initLoginUserResourceList(request.getSession());
			resultXml = model2TreeDataFormat.dataFormatModel2Tree(resources);

		} catch (Exception e) {
			e.printStackTrace();
			session.put("exceptionInfoClass", e);
			return "exceptionOperateAction";
		}
		PrintWriter out = response.getWriter();
		out.print(resultXml);
		out.flush();
		out.close();
		return null;
	}

}
